package com.csgc.camera.biz.other.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.csgc.camera.base.BaseBindingActivity
import com.csgc.camera.bean.ChooseMaskStyle
import com.csgc.camera.biz.MainActivity
import com.csgc.camera.biz.other.adapter.ChooseMaskStyleAdapter
import com.csgc.camera.http.viewmodel.AppViewModel
import com.csgc.camera.storage.MaskPreference
import com.cysd.spsyxj.R
import com.cysd.spsyxj.databinding.ActivityChooseMaskStyleBinding
import com.gyf.immersionbar.ktx.immersionBar

class ChooseIdentityActivity: BaseBindingActivity<ActivityChooseMaskStyleBinding>(ActivityChooseMaskStyleBinding::inflate) {

    private val viewModel:AppViewModel by viewModels()

    companion object {
        fun launch(context: Context) {
            context.startActivity(Intent(context, ChooseIdentityActivity::class.java))
        }
    }


    private var identityType = 0
    private var identityId = 0

    private val adapter:ChooseMaskStyleAdapter by lazy {
        val adapter = ChooseMaskStyleAdapter(this, ArrayList())
        adapter.listener = object :ChooseMaskStyleAdapter.OnItemChooseListener{
            override fun onItemChoose(type: Int, id: Int) {
                identityType = type
                identityId = id
            }
        }
        adapter
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        immersionBar {
            fitsSystemWindows(true)

            statusBarColor(R.color.white)
            statusBarDarkFont(true)
        }

        initView()
        intiListener()
    }

    private fun intiListener() {
        binding.tvJumpMain.setOnClickListener {
            MaskPreference.instance.setIdentityId(identityId)
            MaskPreference.instance.setIdentityType(identityType)
            MainActivity.launch(this)
            finish()
        }
    }

    private fun initView() {
        binding.apply {
            tvJumpMain.visibility = View.VISIBLE
            tvTitle.text = "选择身份"
            rvMaskTypeList.layoutManager = LinearLayoutManager(this@ChooseIdentityActivity)
            rvMaskTypeList.adapter = adapter
            adapter.setCheckedPosition(0)
            adapter.updateContent(viewModel.getIdentityList() as ArrayList<ChooseMaskStyle>)
        }
    }


}